
local heal = class('heal')

heal.type = 'heal'							    --类型
heal.source = nil								--来源
heal.target = nil								--目标
heal.reason = '未知'							    --原因
heal.heal = 0									--治疗
heal.skill = nil								--关联技能

function heal:ctor(data)
    if data then
        if data.type   then self.type    = data.type    end
        if data.source then self.source  = data.source  end
        if data.target then self.target  = data.target  end
        if data.reason then self.reason  = data.reason  end
        if data.heal   then self.heal    = data.heal    end
        if data.skill  then self.skill   = data.skill   end
    end
end

--创建漂浮文字
local function text(heal)
	if heal.target ~= g_playerMgr.self.hero then
		return
	end
	local tag = heal.target.heal_texttag
	if tag and ac.clock() - tag.time < 2000 then
		tag.heal = tag.heal + heal.heal
		tag:setText(('%.f'):format(tag.heal), 8 + (tag.heal ^ 0.5) / 5)
	else
		local x, y = heal.target:get_point():get()
		local z = heal.target:get_point():getZ()
		local tag = ac.texttag
		{
			string = ('+%.f'):format(heal.heal),
			size = 8 + (heal.heal ^ 0.5) / 5,
			position = ac.point(x - 60, y, z - 30),
			speed = 86,
			angle = -45,
			red = 20,
			green = 100,
			blue = 20,
			heal = heal.heal,
			time = ac.clock(),
		}
		heal.target.heal_texttag = tag
	end
end

--创建治疗
function heal:__call(data)
	if not data.target or data.heal == 0 then
		return
	end

	if data.skill == nil then
		log.warnning('治疗没有关联技能')
		log.warnning(debug.traceback())
	end
	
	local h = heal.new(data)

	if h.target:event_dispatch('受到治疗开始', h) then
		return h
	end

	if h.heal < 0 then
		h.heal = 0
	end
	
	--进行治疗
	h.target:add('生命', h.heal)

	--创建漂浮文字
	text(h)

	h.target:event_notify('受到治疗效果', h)

	return h
end

ac.heal = heal

return heal